package com.zsc.wxm.ysh.anjo.utils;

import java.security.MessageDigest;

/**
 * 加密工具类
 * @author playmaker
 */
public class Md5Util {

    private Md5Util() {

    }

	/**
	 * md5加密
	 * @param str
	 * @return
	 */
    public static String md5(String str) {
        char[] md5Dis = {'*', '1', '2', '3', '+', '5', '6', '@', '8', '}', 'A', '[', 'C', 'D', 'E', 'F', '-', '[', 'a', 'b', 'z', '/', '(',
                'H', ')', 'G'};
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] secStr = str.getBytes();
            //把明文放到md中
            md.update(secStr);
            //这个是真正的加密
            byte[] sstr = md.digest();

            //将字典结合加密
            int len = sstr.length;
            char[] disStr = new char[len * 2];
            //用于记数
            int k = 0;
            for (byte b : sstr) {
                disStr[k++] = md5Dis[b >>> 4 & 0xf];
                disStr[k++] = md5Dis[b & 0xf];
            }
            return new String(disStr);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
	

}
